/*
 * Copyright 2012 Faculty of Informatics - Masaryk University.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.muni.fi.pa165.creatures.model.web;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * Association entity between
 * {@link cz.muni.fi.pa165.creatures.model.web.Person} and
 * {@link cz.muni.fi.pa165.creatures.model.web.Function}.
 *
 * @author smikloso
 */
@Entity
@Table(name = "PERSON_FUNC")
public class PersonFunction implements Serializable {

    private static final long serialVersionUID = 4518547901634917404L;

    @EmbeddedId
    protected PersonFunctionPK personFunctionPK;

    public PersonFunction() {
    }

    public PersonFunction(PersonFunctionPK personFunctionPK) {
        this.personFunctionPK = personFunctionPK;
    }

    public PersonFunction(Long personId, Long functionId) {
        this.personFunctionPK = new PersonFunctionPK(personId, functionId);
    }

    public PersonFunctionPK getPersonFunctionPK() {
        return personFunctionPK;
    }

    public void setPersonFunctionPK(PersonFunctionPK personFunctionPK) {
        this.personFunctionPK = personFunctionPK;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 23 * hash + (this.personFunctionPK != null ? this.personFunctionPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof PersonFunction)) {
            return false;
        }
        PersonFunction other = (PersonFunction) obj;

        if ((this.personFunctionPK == null && other.personFunctionPK != null)
                || (this.personFunctionPK != null
                && !this.personFunctionPK.equals(other.personFunctionPK))) {
            return false;
        }
        return true;
    }
}
